package com.szosen.jkzj.activity.ggws;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.szosen.application.MyApplication;
import com.szosen.database.DBService;
import com.szosen.database.OldPeopleSelfCare;
import com.szosen.jkzj.R;
import com.szosen.jkzj.activity.BaseActivity;
import com.szosen.json.OldAssessment;
import com.szosen.util.BackGroundThread;
import com.szosen.util.BackGroundThread.BackGroundTask;
import com.szosen.util.JktjBitmapUtil;
import com.szosen.util.TimeHelper;
import com.szosen.util.ToastTool;
import com.szosen.web.WebService;
import com.szosen.xml.XmlTool;

import java.util.List;

/***
 * 老年人生活自理能力
 *
 * @author geshenjibi
 *
 */
public class Lnrshzlnl extends BaseActivity {
	// 进餐 meal
	private RadioGroup mMealRG;
	private RadioButton mMealRG0;
	private RadioButton mMealRG1;
	private RadioButton mMealRG2;
	private TextView mMealEstimateTV;
	private int mealRate = -1;

	// 梳洗 wash
	private RadioGroup mWashRG;
	private RadioButton mWashRG0;
	private RadioButton mWashRG1;
	private RadioButton mWashRG2;
	private RadioButton mWashRG3;
	private TextView mWashEstimateTV;
	private int washRate = -1;

	// 穿衣 dress
	private RadioGroup mDressRG;
	private RadioButton mDressRG0;
	private RadioButton mDressRG1;
	private RadioButton mDressRG2;
	private TextView mDressEstimateTV;
	private int dressRate = -1;

	// 如厕 toilet
	private RadioGroup mToiletRG;
	private RadioButton mToiletRG0;
	private RadioButton mToiletRG1;
	private RadioButton mToiletRG2;
	private RadioButton mToiletRG3;
	private TextView mToiletEstimateTV;
	private int toiletRate = -1;

	// 活动 exercise
	private RadioGroup mExerciseRG;
	private RadioButton mExerciseRG0;
	private RadioButton mExerciseRG1;
	private RadioButton mExerciseRG2;
	private RadioButton mExerciseRG3;
	private TextView mExerciseEstimateTV;
	private int exerciseRate = -1;

	// 总评分
	private int totalRate;
	private TextView mTotalEstimateTV;
	private String totalEstimate = null;
	private Button mShowEstimatBtn;

	// 表中属性
	private ContentValues cv = new ContentValues();
	private SQLiteDatabase db;
	private Cursor cursor;
	private String table = "oldPeopleSelfCareEstimate";
	private boolean isExisted = false;
	private Button saveTableBtn;
	private Button lnrshzlnl_btn_print;
	private OldPeopleSelfCare oldPeopleSelfCare;
	private String date = "";// 建表的日期
	private EditText lnrshzlnl_date;
	private String time;
	private EditText inputUnit;
	private EditText inputUser;
	private EditText lastModifyUser;
	private EditText lastModifyUnit;
	private EditText lastModifyDate;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ggws_lnrshzlnl_activity);
		super.setTitleContent("【老年人生活自理能力】");
		findView(this);
		initData();
		fillTable();// 从数据库填充数据。

	}

	/***
	 * 检查编辑框。是否可以编辑的。
	 *
	 * @return
	 */
	public boolean isEditTextOK() {
		if (TextUtils.isEmpty(getTextById(R.id.lnrshzlnl_date))) {
			ToastTool.showShort(context, "填表日期不能为空！");
			return false;
		}
		return true;
	}

	private void getAllScore() {
		if (mealRate >= 0 && washRate >= 0 && dressRate >= 0 && toiletRate >= 0
				&& exerciseRate >= 0) {
			totalRate = mealRate + washRate + dressRate + toiletRate
					+ exerciseRate;
			oldPeopleSelfCare.setZPFS(totalRate + "");
			String dengji = "";
			if (totalRate < 4) {
				totalEstimate = totalRate + "\t可自理";
				dengji = "1";
			} else if (totalRate < 9) {
				dengji = "2";
				totalEstimate = totalRate + "\t轻度依赖";
			} else if (totalRate < 19) {
				dengji = "3";
				totalEstimate = totalRate + "\t中度依赖";
			} else {
				dengji = "4";
				totalEstimate = totalRate + "\t不能自理";
			}
			oldPeopleSelfCare.setZP(dengji);
			oldPeopleSelfCare.setZPDJ(dengji);
			oldPeopleSelfCare.setZPFS(totalRate + "");
			mTotalEstimateTV.setText(totalEstimate);
		} else {
			Toast toast = Toast.makeText(Lnrshzlnl.this, "您还未填完整个表，请先填完表格",
					Toast.LENGTH_LONG);
			toast.show();
		}
	}

	/** 在oncreate初始化 */
	private void initData() {
		oldPeopleSelfCare = new OldPeopleSelfCare();
		mShowEstimatBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				getAllScore();
			}
		});


		// 进餐 meal：使用餐具将饭菜送入口、咀嚼、吞咽等活动

		mMealRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.meal_rg0:
					mMealEstimateTV.setText("评分：0\t可自理");
					mealRate = 0;
					oldPeopleSelfCare.setJC("1");
					oldPeopleSelfCare.setJCDJ("1");
					oldPeopleSelfCare.setJCPF("0");
					break;
				case R.id.meal_rg1:
					mMealEstimateTV.setText("评分：3\t中度依赖");
					mealRate = 3;
					oldPeopleSelfCare.setJC("3");
					oldPeopleSelfCare.setJCDJ("3");
					oldPeopleSelfCare.setJCPF("3");
					break;
				case R.id.meal_rg2:
					mMealEstimateTV.setText("评分：5\t不能自理");
					mealRate = 5;
					oldPeopleSelfCare.setJC("4");
					oldPeopleSelfCare.setJCDJ("4");
					oldPeopleSelfCare.setJCPF("5");
					break;
				default:
					break;
				}
			}
		});

		// 梳洗 wash：梳头、洗脸、刷牙、剃须洗澡等活动

		mWashRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.wash_rg0:
					mWashEstimateTV.setText("评分：0\t可自理");
					washRate = 0;
					oldPeopleSelfCare.setSX("1");
					oldPeopleSelfCare.setSXDJ("1");
					oldPeopleSelfCare.setSXPF("0");
					break;
				case R.id.wash_rg1:
					mWashEstimateTV.setText("评分：1\t轻度依赖");
					washRate = 1;
					oldPeopleSelfCare.setSX("2");
					oldPeopleSelfCare.setSXDJ("2");
					oldPeopleSelfCare.setSXPF("1");
					break;
				case R.id.wash_rg2:
					mWashEstimateTV.setText("评分：3\t中度依赖");
					washRate = 3;
					oldPeopleSelfCare.setSX("3");
					oldPeopleSelfCare.setSXDJ("3");
					oldPeopleSelfCare.setSXPF("3");
					break;
				case R.id.wash_rg3:
					mWashEstimateTV.setText("评分：7\t不能自理");
					washRate = 7;
					oldPeopleSelfCare.setSX("4");
					oldPeopleSelfCare.setSXDJ("4");
					oldPeopleSelfCare.setSXPF("7");
					break;
				default:
					break;
				}
			}
		});

		// 穿衣 dress：穿衣裤、袜子、鞋子等活动

		mDressRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.dress_rg0:
					mDressEstimateTV.setText("评分：0\t可自理");
					dressRate = 0;
					oldPeopleSelfCare.setCY("1");
					oldPeopleSelfCare.setCYDJ("1");
					oldPeopleSelfCare.setCYPF("0");
					break;
				case R.id.dress_rg1:
					mDressEstimateTV.setText("评分：3\t中度依赖");
					dressRate = 3;
					oldPeopleSelfCare.setCY("3");
					oldPeopleSelfCare.setCYDJ("3");
					oldPeopleSelfCare.setCYPF("3");
					break;
				case R.id.dress_rg2:
					mDressEstimateTV.setText("评分：5\t不能自理");
					dressRate = 5;
					oldPeopleSelfCare.setCY("4");
					oldPeopleSelfCare.setCYDJ("4");
					oldPeopleSelfCare.setCYPF("5");
					break;
				default:
					break;
				}

			}
		});

		// 如厕 toilet：小便、大便等活动及自控

		mToiletRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.toilet_rg0:
					mToiletEstimateTV.setText("评分：0\t可自理");
					toiletRate = 0;
					oldPeopleSelfCare.setRC("1");
					oldPeopleSelfCare.setRCDJ("1");
					oldPeopleSelfCare.setRCPF("0");
					break;
				case R.id.toilet_rg1:
					mToiletEstimateTV.setText("评分：1\t轻度依赖");
					toiletRate = 1;
					oldPeopleSelfCare.setRC("2");
					oldPeopleSelfCare.setRCDJ("2");
					oldPeopleSelfCare.setRCPF("1");
					break;
				case R.id.toilet_rg2:
					mToiletEstimateTV.setText("评分：5\t中度依赖");
					toiletRate = 5;
					oldPeopleSelfCare.setRC("3");
					oldPeopleSelfCare.setRCDJ("3");
					oldPeopleSelfCare.setRCPF("5");
					break;
				case R.id.toilet_rg3:
					mToiletEstimateTV.setText("评分：10\t不能自理");
					toiletRate = 10;
					oldPeopleSelfCare.setRC("4");
					oldPeopleSelfCare.setRCDJ("4");
					oldPeopleSelfCare.setRCPF("10");
					break;
				default:
					break;
				}
			}
		});

		// 活动 exercise：站立、室内行走、上下楼梯、户外活动

		mExerciseRG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.exercise_rg0:
					mExerciseEstimateTV.setText("评分：0\t可自理");
					exerciseRate = 0;
					oldPeopleSelfCare.setHD("1");
					oldPeopleSelfCare.setHDDJ("1");
					oldPeopleSelfCare.setHDPF("0");
					break;
				case R.id.exercise_rg1:
					mExerciseEstimateTV.setText("评分：1\t轻度依赖");
					exerciseRate = 1;
					oldPeopleSelfCare.setHD("2");
					oldPeopleSelfCare.setHDDJ("2");
					oldPeopleSelfCare.setHDPF("1");
					break;
				case R.id.exercise_rg2:
					mExerciseEstimateTV.setText("评分：5\t中度依赖");
					exerciseRate = 5;
					oldPeopleSelfCare.setHD("3");
					oldPeopleSelfCare.setHDDJ("3");
					oldPeopleSelfCare.setHDPF("5");
					break;
				case R.id.exercise_rg3:
					mExerciseEstimateTV.setText("评分：10\t不能自理");
					exerciseRate = 10;
					oldPeopleSelfCare.setHD("4");
					oldPeopleSelfCare.setHDDJ("4");
					oldPeopleSelfCare.setHDPF("10");
					break;
				default:
					break;
				}
			}
		});
		lnrshzlnl_btn_print.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				getAllScore();
				if (mealRate >= 0 && washRate >= 0 && dressRate >= 0
						&& toiletRate >= 0 && exerciseRate >= 0) {
					String dengji = "";
					if (totalEstimate == null) {
						totalRate = mealRate + washRate + dressRate
								+ toiletRate + exerciseRate;
						if (totalRate < 4) {
							dengji = "1";
							totalEstimate = totalRate + "\t可自理";
						} else if (totalRate < 9) {
							dengji = "2";
							totalEstimate = totalRate + "\t轻度依赖";
						} else if (totalRate < 19) {
							dengji = "3";
							totalEstimate = totalRate + "\t中度依赖";
						} else {
							dengji = "4";
							totalEstimate = totalRate + "\t不能自理";
						}
						oldPeopleSelfCare.setZP(dengji);
						oldPeopleSelfCare.setZPDJ(dengji);
					}
					oldPeopleSelfCare.setZPFS(totalRate + "");
					if (!isEditTextOK()) {
						return;
					}
					// 如果是没设置时间的。就设置一个特定的时间。
					// if (TextUtils.isEmpty(dataTime)) {
					// dataTime = TimeHelper.getJKTJCheckTime();
					// }
					date = lnrshzlnl_date.getText().toString();
					new BackGroundThread(new BackGroundTask() {
						@Override
						public void process() {
							oldPeopleSelfCare.setInputDate(date);
							oldPeopleSelfCare.setTime(time);
							oldPeopleSelfCare.setCheckid(time);
							oldPeopleSelfCare.setIdCard(BaseActivity.getIdCard());
							oldPeopleSelfCare.setInputUnit(getTextByEt(inputUnit));
							oldPeopleSelfCare.setInputUser(getTextByEt(inputUser));
							oldPeopleSelfCare
									.setLastModifyUser(getTextByEt(lastModifyUser));
							oldPeopleSelfCare
									.setLastModifyUnit(getTextByEt(lastModifyUnit));
							oldPeopleSelfCare
									.setLastModifyDate(getTextByEt(lastModifyDate));

							mTotalEstimateTV.setText(totalEstimate);
							String uploadStr = XmlTool
									.Lnrshzlnl2String(oldPeopleSelfCare);
							boolean b = DBService.add(oldPeopleSelfCare);
							OldAssessment oa = new OldAssessment();
							oa.setFood(oldPeopleSelfCare.getJC());
							oa.setFoodLevel(oldPeopleSelfCare.getJCPF());
							oa.setWash(oldPeopleSelfCare.getSX());
							oa.setWashLevel(oldPeopleSelfCare.getSXPF());
							oa.setClothes(oldPeopleSelfCare.getCY());
							oa.setClothesLevel(oldPeopleSelfCare.getCYPF());
							oa.setToilet(oldPeopleSelfCare.getRC());
							oa.setToiletLevel(oldPeopleSelfCare.getRCPF());
							oa.setActivities(oldPeopleSelfCare.getHD());
							oa.setActivitiesLevel(oldPeopleSelfCare.getHDPF());
							oa.setSelfCareAbilityLevel(oldPeopleSelfCare.getZPFS());
							oa.setEmpiId(time);
//							oa.setPhrId(phrId)
							oa.setInputUnit(MyApplication.getOngovId());
							oa.setInputUser(MyApplication.getOnDoctorId());
							oa.setLastModifyUser(MyApplication.getOnDoctorId());
							oa.setLastModifyUnit(MyApplication.getOngovId());
							oa.setLastModifyDate(oldPeopleSelfCare.getInputDate());
							oa.setInputDate(oldPeopleSelfCare.getInputDate());
							oa.setIdCard(BaseActivity.getIdCard());
							JktjBitmapUtil.createLNRSHZLNL_Bitmap(context, oa);
						}
					}).start();
				} else {
					Toast toast = Toast.makeText(Lnrshzlnl.this,
							"您还未填完整个表，请先填完表格", Toast.LENGTH_LONG);
					toast.show();
				}
			}
		});
		saveTableBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				getAllScore();
				if (mealRate >= 0 && washRate >= 0 && dressRate >= 0
						&& toiletRate >= 0 && exerciseRate >= 0) {
					String dengji = "";
					if (totalEstimate == null) {
						totalRate = mealRate + washRate + dressRate
								+ toiletRate + exerciseRate;
						if (totalRate < 4) {
							dengji = "1";
							totalEstimate = totalRate + "\t可自理";
						} else if (totalRate < 9) {
							dengji = "2";
							totalEstimate = totalRate + "\t轻度依赖";
						} else if (totalRate < 19) {
							dengji = "3";
							totalEstimate = totalRate + "\t中度依赖";
						} else {
							dengji = "4";
							totalEstimate = totalRate + "\t不能自理";
						}
						oldPeopleSelfCare.setZP(dengji);
						oldPeopleSelfCare.setZPDJ(dengji);
					}
					oldPeopleSelfCare.setZPFS(totalRate + "");
					if (!isEditTextOK()) {
						return;
					}
					// 如果是没设置时间的。就设置一个特定的时间。
					// if (TextUtils.isEmpty(dataTime)) {
					// dataTime = TimeHelper.getJKTJCheckTime();
					// }
					date = lnrshzlnl_date.getText().toString();
					oldPeopleSelfCare.setInputDate(date);
					oldPeopleSelfCare.setTime(time);
					oldPeopleSelfCare.setCheckid(time);
					oldPeopleSelfCare.setIdCard(BaseActivity.getIdCard());
					oldPeopleSelfCare.setInputUnit(getTextByEt(inputUnit));
					oldPeopleSelfCare.setInputUser(getTextByEt(inputUser));
					oldPeopleSelfCare
							.setLastModifyUser(getTextByEt(lastModifyUser));
					oldPeopleSelfCare
							.setLastModifyUnit(getTextByEt(lastModifyUnit));
					oldPeopleSelfCare
							.setLastModifyDate(getTextByEt(lastModifyDate));

					mTotalEstimateTV.setText(totalEstimate);
					String uploadStr = XmlTool
							.Lnrshzlnl2String(oldPeopleSelfCare);
					boolean b = DBService.add(oldPeopleSelfCare);
					OldAssessment oa = new OldAssessment();
					oa.setFood(oldPeopleSelfCare.getJC());
					oa.setFoodLevel(oldPeopleSelfCare.getJCPF());
					oa.setWash(oldPeopleSelfCare.getSX());
					oa.setWashLevel(oldPeopleSelfCare.getSXPF());
					oa.setClothes(oldPeopleSelfCare.getCY());
					oa.setClothesLevel(oldPeopleSelfCare.getCYPF());
					oa.setToilet(oldPeopleSelfCare.getRC());
					oa.setToiletLevel(oldPeopleSelfCare.getRCPF());
					oa.setActivities(oldPeopleSelfCare.getHD());
					oa.setActivitiesLevel(oldPeopleSelfCare.getHDPF());
					oa.setSelfCareAbilityLevel(oldPeopleSelfCare.getZPFS());
					oa.setEmpiId(time);
//					oa.setPhrId(phrId)
					oa.setInputUnit(MyApplication.getOngovId());
					oa.setInputUser(MyApplication.getOnDoctorId());
					oa.setLastModifyUser(MyApplication.getOnDoctorId());
					oa.setLastModifyUnit(MyApplication.getOngovId());
					oa.setLastModifyDate(oldPeopleSelfCare.getInputDate());
					oa.setInputDate(oldPeopleSelfCare.getInputDate());
					oa.setIdCard(BaseActivity.getIdCard());
					final String uploadTime = time;
					WebService.addOldAssessment(context, uploadTime,
							jsonHandler, oa);
				} else {
					Toast toast = Toast.makeText(Lnrshzlnl.this,
							"您还未填完整个表，请先填完表格", Toast.LENGTH_LONG);
					toast.show();
				}
			}
		});

	}

	private static final int what_success_ok = 65;
	private static final int what_failed = 77;
	private static final int what_error = 87;
	Handler jsonHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case what_success_ok:
				ToastTool.showLong(context, "上传成功");
				break;
			case what_failed:
				ToastTool.showLong(context, "上传错误");
				break;
			case what_error:
				ToastTool.showLong(context, "访问出错，请检查网络或配置信息");
				break;
			}
		};
	};

	private void fillTable() {
		time = getIntent().getStringExtra("time");
		if (TextUtils.isEmpty(time)) {
			time = TimeHelper.getMainTimeKey();
			setText(R.id.lnrshzlnl_date, TimeHelper.getJKTJCheckDate());
		}
		OldPeopleSelfCare queryObj = new OldPeopleSelfCare();
		// queryObj.setIdCard(BaseActivity.getIdCard());
		if (TextUtils.isEmpty(time)) {
			time = TimeHelper.getMainTimeKey();
		}
		queryObj.setTime(time);
		List<Object> lists = (List<Object>) DBService.queryByKey(queryObj);
		OldPeopleSelfCare bean;
		if (lists.size() > 0) {
			bean = (OldPeopleSelfCare) lists.get(0);
		} else {
			return;
		}
		// 从数据库获取正式的时间。
		date = bean.getInputDate();
		setText(R.id.lnrshzlnl_date, date);
		// 进餐
		String jincan = bean.getJC();
		switch (jincan) {
		case "1":
			mMealRG0.setChecked(true);
			mealRate = 0;
			break;
		case "3":
			mMealRG1.setChecked(true);
			mealRate = 3;
			break;
		case "4":
			mMealRG2.setChecked(true);
			mealRate = 5;
			break;
		default:
			break;
		}

		// 梳洗
		String shuxi = bean.getSX();
		switch (shuxi) {
		case "1":
			mWashRG0.setChecked(true);
			washRate = 0;
			break;
		case "2":
			mWashRG1.setChecked(true);
			washRate = 1;
			break;
		case "3":
			mWashRG2.setChecked(true);
			washRate = 3;
			break;
		case "4":
			mWashRG3.setChecked(true);
			washRate = 7;
			break;
		default:
			break;
		}
		// 穿衣
		String chuanyi = bean.getCY();
		// dress
		switch (chuanyi) {
		case "1":
			mDressRG0.setChecked(true);
			dressRate = 0;
			break;
		case "3":
			mDressRG1.setChecked(true);
			dressRate = 3;
			break;
		case "4":
			mDressRG2.setChecked(true);
			dressRate = 5;
			break;
		default:
			break;
		}

		// 如厕
		String ruce = bean.getRC();
		switch (ruce) {
		case "1":
			mToiletRG0.setChecked(true);
			toiletRate = 0;
			break;
		case "2":
			mToiletRG1.setChecked(true);
			toiletRate = 1;
			break;
		case "3":
			mToiletRG2.setChecked(true);
			toiletRate = 5;
			break;
		case "4":
			mToiletRG3.setChecked(true);
			toiletRate = 10;
			break;
		default:
			break;
		}
		// 活动
		String huodong = bean.getHD();
		switch (huodong) {
		case "1":
			mExerciseRG0.setChecked(true);
			exerciseRate = 0;
			break;
		case "2":
			mExerciseRG1.setChecked(true);
			exerciseRate = 1;
			break;
		case "3":
			mExerciseRG2.setChecked(true);
			exerciseRate = 5;
			break;
		case "4":
			mExerciseRG3.setChecked(true);
			exerciseRate = 10;
			break;
		default:
			break;
		}
		inputUnit.setText(bean.getInputUnit());
		inputUser.setText(bean.getInputUser());
		lastModifyUser.setText(bean.getLastModifyUser());
		lastModifyUnit.setText(bean.getLastModifyUnit());
		lastModifyDate.setText(bean.getLastModifyDate());

		String zongfen = bean.getZPFS();
		if (TextUtils.isEmpty(zongfen)) {
			mTotalEstimateTV.setText("");
			return;
		}
		try {
			int zongfenInt = Integer.valueOf(zongfen);
			if (zongfenInt < 4) {
				totalEstimate = zongfen + "\t可自理";
			} else if (zongfenInt < 9) {
				totalEstimate = zongfen + "\t轻度依赖";
			} else if (zongfenInt < 19) {
				totalEstimate = zongfen + "\t中度依赖";
			} else {
				totalEstimate = zongfen + "\t不能自理";
			}
			mTotalEstimateTV.setText(totalEstimate);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private void findView(Activity v) {
		inputUnit = (EditText) findViewById(R.id.inputUnit);
		inputUser = (EditText) findViewById(R.id.inputUser);
		lastModifyUser = (EditText) findViewById(R.id.lastModifyUser);
		lastModifyUnit = (EditText) findViewById(R.id.lastModifyUnit);
		lastModifyDate = (EditText) findViewById(R.id.lastModifyDate);
		lnrshzlnl_date = (EditText) v.findViewById(R.id.lnrshzlnl_date);
		mMealRG0 = (RadioButton) v.findViewById(R.id.meal_rg0);
		mMealRG1 = (RadioButton) v.findViewById(R.id.meal_rg1);
		mMealRG2 = (RadioButton) v.findViewById(R.id.meal_rg2);

		mWashRG0 = (RadioButton) v.findViewById(R.id.wash_rg0);
		mWashRG1 = (RadioButton) v.findViewById(R.id.wash_rg1);
		mWashRG2 = (RadioButton) v.findViewById(R.id.wash_rg2);
		mWashRG3 = (RadioButton) v.findViewById(R.id.wash_rg3);

		mDressRG0 = (RadioButton) v.findViewById(R.id.dress_rg0);
		mDressRG1 = (RadioButton) v.findViewById(R.id.dress_rg1);
		mDressRG2 = (RadioButton) v.findViewById(R.id.dress_rg2);

		mToiletRG0 = (RadioButton) v.findViewById(R.id.toilet_rg0);
		mToiletRG1 = (RadioButton) v.findViewById(R.id.toilet_rg1);
		mToiletRG2 = (RadioButton) v.findViewById(R.id.toilet_rg2);
		mToiletRG3 = (RadioButton) v.findViewById(R.id.toilet_rg3);

		mExerciseRG0 = (RadioButton) v.findViewById(R.id.exercise_rg0);
		mExerciseRG1 = (RadioButton) v.findViewById(R.id.exercise_rg1);
		mExerciseRG2 = (RadioButton) v.findViewById(R.id.exercise_rg2);
		mExerciseRG3 = (RadioButton) v.findViewById(R.id.exercise_rg3);

		saveTableBtn = (Button) v.findViewById(R.id.save_table_btn);
		lnrshzlnl_btn_print = (Button) v.findViewById(R.id.lnrshzlnl_btn_print);
		mTotalEstimateTV = (TextView) v.findViewById(R.id.total_estimate_tv);
		mShowEstimatBtn = (Button) v.findViewById(R.id.show_estimate_btn);
		mMealRG = (RadioGroup) v.findViewById(R.id.meal_rg);
		mMealEstimateTV = (TextView) v.findViewById(R.id.meal_estimate_tv);
		mWashRG = (RadioGroup) v.findViewById(R.id.wash_rg);
		mWashEstimateTV = (TextView) v.findViewById(R.id.wash_estimate_tv);
		mDressRG = (RadioGroup) v.findViewById(R.id.dress_rg);
		mDressEstimateTV = (TextView) v.findViewById(R.id.dress_estimate_tv);
		mToiletRG = (RadioGroup) v.findViewById(R.id.toilet_rg);
		mToiletEstimateTV = (TextView) v.findViewById(R.id.toilet_estimate_tv);
		mExerciseEstimateTV = (TextView) v
				.findViewById(R.id.exercise_estimate_tv);
		mExerciseRG = (RadioGroup) v.findViewById(R.id.exercise_rg);
	}

}
